<?php
class LMessage extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'LMessage';
    }

    public function rules()
    {

        return array(
                array('language, translation, message_source_id', 'required'),
                array('language, message_source_id', 'numerical', 'integerOnly'=>true),
                array('id, language, translation, message_source_id', 'safe', 'on'=>'search'),
        );
    }

    public function relations()
    {
        return array(
                'messLang' => array(self::BELONGS_TO, 'Language', 'language'),
                'messageSource' => array(self::BELONGS_TO, 'LSourceMessage', 'message_source_id'),
        );
    }

    public function attributeLabels()
    {
        return array(
                'id'                => 'ID',
                'language'          => Yii::t('language', 'Язык'),
                'translation'       => Yii::t('language', 'Перевод'),
                'message_source_id' => Yii::t('language', 'Языковая метка'),
        );
    }

    public function dropDownItemsAll(){
        $items= Array();
        $model = self::model()->findAll();
        foreach ($model as $value) {
            $items[$value->id] = $value->id;
        }
        return $items;
    }

    public function search()
    {	
        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('language',$this->language);
        $criteria->compare('translation',$this->translation,true);
        $criteria->compare('message_source_id',$this->message_source_id);

        return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
        ));
    }
}